package com.hospitalsystem.controller;

import com.hospitalsystem.entity.CheckList;
import com.hospitalsystem.service.CheckListService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (CheckList)表控制层
 *
 * @author makejava
 * @since 2024-12-28 19:31:41
 */
@RestController
@RequestMapping("checkList")
public class CheckListController {
    /**
     * 服务对象
     */
    @Resource
    private CheckListService checkListService;

    /**
     * 分页查询
     *
     * @param page
     * @param size
     *
     * @return 查询结果
     */
    @GetMapping("/getAllCheckByPage")
    public ResponseEntity<Page<CheckList>> queryByPage(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int size) {
        PageRequest pageRequest = PageRequest.of(page, size);
        return ResponseEntity.ok(this.checkListService.queryByPage(pageRequest));
    }

    /**
     * 直接查询
     *
     * @return 查询结果
     */
    @GetMapping("/getAllCheck")
    public ResponseEntity<List<CheckList>> findAll() {
        return ResponseEntity.ok(this.checkListService.findAll());
    }

    /**
     * 通过主键查询单条数据
     *
     * @param checkId
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<CheckList> queryById(@PathVariable("id") String checkId) {
        return ResponseEntity.ok(this.checkListService.queryById(checkId));
    }

    /**
     * 新增数据
     *
     * @param checkList 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<CheckList> add(CheckList checkList) {
        return ResponseEntity.ok(this.checkListService.insert(checkList));
    }

    /**
     * 编辑数据
     *
     * @param checkList 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<CheckList> edit(CheckList checkList) {
        return ResponseEntity.ok(this.checkListService.update(checkList));
    }

    /**
     * 删除数据
     *
     * @param checkId
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(String checkId) {
        return ResponseEntity.ok(this.checkListService.deleteById(checkId));
    }

}

